package com.rt.tmpt.controller.springmvc.admin;


import com.rt.tmpt.dto.Result;
import com.rt.tmpt.service.IChartService;
import com.rt.tmpt.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@ApiIgnore
@Controller
@RequestMapping("/admin123/template/charts/")
@Slf4j
public class ChartAction{
	/*private String _keyRandom;
	private String targetTableId;
	private String chartColumn;//single chart: "dataCompanyB"*/

	/*private String result;
	private List<Map<String,Object>> jsonArrayResult = new ArrayList<Map<String,Object>>();*/

    @Resource
    IChartService chartService;


    /**
     * @return
     */
	@RequestMapping(value = "/chartAjax_chartMultiJson", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String chartMultiJson(String _keyRandom){


		Result resultObj = new Result();
		String result;
		try {
			resultObj = chartService.chartMultiJson(_keyRandom);
			String chartJson  = resultObj.getRemark();

	    	result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			result = "error:操作失败："+e.getLocalizedMessage();
		}
		return result;
	}

	@RequestMapping(value = "/chartAjax_chartSingleJson", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String chartSingleJson(String _keyRandom, String chartColumn){
		Result resultObj = new Result();
		String result;
		try {
			resultObj = chartService.chartSingleJson(_keyRandom,chartColumn);
			String chartJson  = resultObj.getRemark();

	    	result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			result = "error:操作失败："+e.getLocalizedMessage();
		}
		return result;
	}


	@RequestMapping(value = "/chartAjax_chartPieJson", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String chartPieJson(String targetTableId, String _keyRandom){
		Result resultObj = new Result();
		String result;
		try {
			targetTableId = StringUtils.isNull(targetTableId)?"0":targetTableId;
			int targetTableIdInt = Integer.parseInt(targetTableId);
			resultObj = chartService.chartPieJson(_keyRandom,targetTableIdInt);
			String chartJson  = resultObj.getRemark();

	    	result = chartJson;
		}catch (Exception e) {
			e.printStackTrace();
			result = "error:操作失败："+e.getLocalizedMessage();
		}
		return result;
	}





}
